/*
 *  token.h
 *  Fib
 *
 *  Created by John Bassham on 11/13/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef TOKEN_H_
#define TOKEN_H_

#include <stdio.h>

#include "bool.h"

enum token_error {
	TOKENERROR_NULL_TOKEN		= 0,
	TOKENERROR_MALFORMED_INDENTATION,
	TOKENERROR_UNRECOGNIZED_OPER
};

enum token_type {
	TOKENTYPE_ERROR = 0,
	TOKENTYPE_LINE,
	TOKENTYPE_OPER,
	TOKENTYPE_IDENT,
	TOKENTYPE_KEYWD,
	TOKENTYPE_NUMLIT,
	TOKENTYPE_STRLIT
};

struct token {
	enum token_type type;
	void *value;
};

struct token_errors_struct {
	const enum token_error null_token;
	const enum token_error malformed_indentation;
	const enum token_error unrecognized_oper;
};

struct tokenizer {
	FILE *file;
	struct token *line_tokens;
	int line_tokens_cnt;
	int line_tokens_bufsz;
	int iter_indx;
	char *buf;
	size_t bufsz;
	bool reached_eof;
	const struct token_errors_struct errors;
};

bool init_tokenizer(struct tokenizer *, FILE *);

const struct token next_token(struct tokenizer *);

#endif
